﻿<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>简睿捷智能制造PDM系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <!-- Bootstrap -->
    <link href="Content/bootstrap.min.css" rel="stylesheet" />
    <script src="Scripts/jquery-1.10.2.min.js"></script>
    <script src="Scripts/bootstrap.min.js"></script>
    <!--angularJS-->
    <script src="Scripts/angular_1.5.8/angular.min.js"></script>
    <script src="Scripts/angular_1.5.8/angular-filter.min.js"></script>
    <!--resizableColumns-->
    <link href="Content/jquery.resizableColumns.css" rel="stylesheet" />
    <script src="js/store.min.js"></script>
    <script src="Scripts/jquery.resizableColumns.min.js"></script>
    <!--jridgecommon.js-->
    <script src="../Scripts/jridgecommon.js"></script>
    <!--文件上传-->
    <script src="../Scripts/stream-v1.js"></script>
    <link href="css/uploadfile.css" rel="stylesheet" />
    <!--AngularJS Service-->
    <script src="../Scripts/service/RightService.js"></script>
    <!--自己写的js和css-->
    <script src="js/pdm.js"></script>
    <link href="css/pdm.css" rel="stylesheet" />

</head>
<body ng-app="myApp" ng-controller="myCtrl" class="container-fluid" id="m">
    <!-------------------------顶部导航栏----------------------->
    <nav class="navbar navbar-default navbar-static-top navbar-fixed-top" role="navigation" id="navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#userinfo">
                    <span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">{{userinfo.clientname}}-简睿捷PDM系统</a>
            </div>
            <div class="collapse navbar-collapse" id="userinfo">
                <ul class="nav navbar-nav">
                    <li><a><span class="glyphicon glyphicon-user"></span> {{userinfo.user.properties.name}}</a></li>
                    <li><a>IP：{{userinfo.ip}}</a></li>
                    <li><a style="cursor:pointer;" href="login.html">退出</a></li>
                    <li>
                        <a class="hidden" id="settings" onclick="window.jcloudandroid.showset();">
                            <span class="glyphicon glyphicon-cog"></span>
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    <!-------------------------顶部功能栏 mobile-------------------------->
    <form class="form mobile" role="form" ng-keydown="keydownSearch()" style="margin-top:5px;margin-bottom:5px;">
        <div class="form-group">
            <div class="input-group">
                <span class="input-group-btn hidden"></span>
                <span class="input-group-btn" style="padding-right:10px;">
                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        <span class="glyphicon glyphicon-tags"></span>
                    </button>
                    <ul class="dropdown-menu">
                        <li ng-repeat="label in labels"><a ng-click="favoriteList($index)">{{label}}</a></li>

                        <li role="separator" class="divider"></li>
                        <li><a></a></li>
                    </ul>
                </span>
                <input type="text" class="form-control" ng-model="keyword" placeholder="关键词" />
                <span class="input-group-btn" style="padding-right:10px;">
                    <button class="btn btn-primary" type="button" ng-click="search()"><span class="glyphicon glyphicon-search"></span></button>
                </span>
                <span class="input-group-btn">
                    <button class="btn btn-default" type="button" ng-click="includePath='list-view.html'" ng-class="{'list-view.html':'active'}[includePath]">
                        <span class="glyphicon glyphicon-th-list"></span>
                    </button>
                </span>
                <span class="input-group-btn">
                    <button class="btn btn-default" type="button" ng-click="includePath='grid-view.html'" ng-class="{'grid-view.html':'active'}[includePath]">
                        <span class="glyphicon glyphicon-th-large"></span>
                    </button>
                </span>
                <span class="input-group-btn">
                    <button class="btn btn-default" data-toggle="collapse" data-target="#filterBody">
                        <span class="glyphicon glyphicon-filter"></span>
                    </button>
                </span>

                <!--文件上传按钮-->
                <!--<span class="input-group-btn">
                    <button class="btn btn-default" type="button" onclick="javascript:window.location.href='phone.html'">
                        <span class="glyphicon glyphicon-camera"></span>
                    </button>
                </span>-->
                <!--文件上传按钮-->
                <div ng-show="enableCamera">
                    <!--已选择文件-->
                    <div id="i_select_files"></div>
                    <div id="i_stream_files_queue" style="display:none"></div>
                    <div id="i_stream_message_container" class="stream-main-upload-box" style="overflow: auto; height: 200px; display: none"></div>
                </div>
                <!--文件上传按钮结束-->

                <span class="input-group-btn hidden"></span>
            </div>
        </div>
    </form>

    

    <!-------------------------标签的添加与删除-------------------------->
    <div class="collapse" id="manageLabel">
        <div class="well">
            <form class="form-inline">
                <div class="btn-group" ng-repeat="label in labels">
                    <button class="btn btn-default">{{label}}</button>
                    <button class="btn btn-danger" ng-click="removeLabel($index)">
                        <span class="glyphicon glyphicon-remove"></span>
                    </button>
                </div>
                &nbsp; &nbsp;
                <div class="form-group">
                    <input type="text" class="form-control" ng-model="labelName" placeholder="标签名" />
                </div>
                <button type="button" class="btn btn-primary" ng-click="addLabel()">
                    <span class="glyphicon glyphicon-plus"></span>
                </button>
                &nbsp; &nbsp; &nbsp; &nbsp;
                <button class="btn btn-success" data-toggle="collapse" data-target="#manageLabel">ok</button>
            </form>
        </div>
    </div>
    <!-------------------------筛选-------------------------->
    <div class="collapse" id="filterBody">
        <div class="well">
            <form>
                <label class="checkbox-inline" ng-repeat="list in metaclass[meta.metaclass.SysDocumentRev].ClassMeta.Class.Properties.Property">
                    <input type="checkbox" ng-model="list['show']" ng-init="checkedname=true" />{{list['@displayname']}}
                </label>

            </form>
            <br />
            <form class="form-inline">
                <div class="form-group">
                    <input type="text" class="form-control" ng-model="fileName" placeholder="文档名称" />
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" ng-model="creator" placeholder="创建人名" />
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" ng-model="createdDate" placeholder="创建时间" />
                </div>
            </form>
        </div>
    </div>
    <!-------------------------路径导航-------------------------->
    <ol class="breadcrumb">
        <li>位置</li>
        <li ng-repeat="curFolderName in curFolderNames">
            <button type="button" class="btn btn-default" ng-click="goBack($index)">{{curFolderName.properties.name}}</button>
        </li>
    </ol>
    <!-------------------------loading动画-------------------------->
    <div ng-if="includePath=='loading.html'" ng-include="'loading.html'"></div>
    <!-------------------------内容部分 list方式显示-------------------------->
    <div ng-if="includePath=='list-view.html'" ng-include="'list-view.html'"></div>
    <!-------------------------内容部分 图片显示-------------------------->
    <div ng-if="includePath=='grid-view.html'" ng-include="'grid-view.html'"></div>
    <!-------------------------文档详情-------------------------->
    <!-------上传确认 modal------->
    <div class="modal fade" id="upload_comfirm" tabindex="-1" role="dialog"
         aria-labelledby="upload_comfirmrModal" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title">上传文件</h4>
                </div>
                <div class="modal-body">
                    <h3>确认上传吗？</h3>
                </div><!-- /.modal-body -->
                <div class="modal-footer">
                    <button type="button" class="btn btn-success navbar-btn" onclick="javascript:_t.upload();">确认上传</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消上传</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <!-------编辑区域 modal------->
    <div class="modal fade" id="edit" tabindex="-1" role="dialog"
         aria-labelledby="editModal" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title">{{obj.properties.name}}</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">
                        <div class="form-group">
                            <div class="row">
                                <label class="col-md-3 control-label">名称：</label>
                                <div class="col-md-7">
                                    <input type="text" class="form-control" ng-model="obj.properties.name" />
                                </div>
                            </div>
                        </div>
                        <div class="form-group" ng-repeat="property in metaclass[obj.type].ClassMeta.Class.Properties.Property">
                            <div class="row">
                                <label class="col-md-3 control-label">{{property['@displayname']}}：</label>
                                <div class="col-md-7">
                                    <input type="text" class="form-control" ng-model="obj.properties[property['@internalName'].toLowerCase()]" />
                                </div>
                            </div>
                        </div>
                    </form>
                </div><!-- /.modal-body -->
                <div class="modal-footer">
                    <div class="row">
                        <!--暂时不开放web端的删除
                            <div class="col-md-6">
                            <button type="button" class="btn btn-danger pull-left" ng-click="onClickDelete()">删除</button>
                        </div>-->
                        <div class="col-md-6">
                            <button type="button" class="btn btn-success" ng-click="onClickSave()">保存</button>
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭窗口</button>
                        </div>
                    </div>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <!-------新建文件夹区域 modal------->
    <div class="modal fade" id="newFolder" tabindex="-1" role="dialog"
         aria-labelledby="newFolderModal" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title">新建文件夹</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">
                        <div class="form-group" ng-repeat="property in metaclass[obj.type].ClassMeta.Class.Properties.Property">
                            <div class="row">
                                <label class="col-md-3 control-label">{{property['@displayname']}}：</label>
                                <div class="col-md-7">
                                    <input type="text" class="form-control" ng-model="obj.properties[property['@internalName'].toLowerCase()]" />
                                </div>
                            </div>
                        </div>
                    </form>
                </div><!-- /.modal-body -->
                <div class="modal-footer">
                    <button type="button" class="btn btn-success navbar-btn" ng-click="batchdoRelation(parentObj,[obj],'PlmFolderHierarchy',17)">保存</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭窗口</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <!----------------------分页--------------------->
    <script>
        $(function () {
            $("#main_list").resizableColumns({
                store: window.store
            });
        });

        /**
* 配置文件（如果没有默认字样，说明默认值就是注释下的值）
* 但是，on*（onSelect， onMaxSizeExceed...）等函数的默认行为
* 是在ID为i_stream_message_container的页面元素中写日志
*/
        var config = {
            browseFileId: "i_select_files", /** 选择文件的ID, 默认: i_select_files */
            browseFileBtn: '<span class="input-group-btn">' +
                '<button class="btn btn-default" type="button">' +
                    '<span class="glyphicon glyphicon-camera"></span>' +
                '</button>' +
           '</span>', /** 显示选择文件的样式, 默认: `<div>请选择文件</div>` */
            dragAndDropArea: "i_select_files", /** 拖拽上传区域，Id（字符类型"i_select_files"）或者DOM对象, 默认: `i_select_files` */
            dragAndDropTips: "<span></span>", /** 拖拽提示, 默认: `<span>把文件(文件夹)拖拽到这里</span>` */
            filesQueueId: "i_stream_files_queue", /** 文件上传容器的ID, 默认: i_stream_files_queue */
            filesQueueHeight: 200, /** 文件上传容器的高度（px）, 默认: 450 */
            messagerId: "i_stream_message_container", /** 消息显示容器的ID, 默认: i_stream_message_container */
            multipleFiles: true, /** 多个文件一起上传, 默认: false */
            autoUploading: true, /** 选择文件后是否自动上传, 默认: true */
            //autoRemoveCompleted: false, /** 是否自动删除容器中已上传完毕的文件, 默认: false */
            //		maxSize: 104857600//, /** 单个文件的最大大小，默认:2G */
            //		retryCount : 5, /** HTML5上传失败的重试次数 */
            //		postVarsPerFile : { /** 上传文件时传入的参数，默认: {} */
            //			param1: "val1",
            //			param2: "val2"
            //		},
            swfURL: "../swf/FlashUploader.swf", /** SWF文件的位置 */
            tokenURL: "../upload/tk", /** 根据文件名、大小等信息获取Token的URI（用于生成断点续传、跨域的令牌） */
            uploadURL: "../upload/file", /** HTML5上传的URI */
            //		frmUploadURL: "FileUpload.ashx?Method=fd;", /** Flash上传的URI */
            //		simLimit: 200, /** 单次最大上传文件个数 */
            extFilters: [".bmp", ".jpg", ".png", ".tiff", ".gif", ".pcx", ".tga", ".exif", ".fpx", ".svg", ".psd", ".cdr", ".pcd", ".dxf", ".ufo", ".eps", ".ai", ".raw", ".WMF"], /** 允许的文件扩展名, 允许上传文件类型默认: [] */
            //onSelect: onSelected, /**function(list) {alert('onSelect')} 选择文件后的响应事件 */
            //		onMaxSizeExceed: function(size, limited, name) {alert('onMaxSizeExceed')}, /** 文件大小超出的响应事件 */
            //		onFileCountExceed: function(selected, limit) {alert('onFileCountExceed')}, /** 文件数量超出的响应事件 */
            //		onExtNameMismatch: function(name, filters) {alert('onExtNameMismatch')}, /** 文件的扩展名不匹配的响应事件 */
            //		onCancel : function(file) {alert('Canceled:  ' + file.name)}, /** 取消上传文件的响应事件 */
            onComplete: CompleteUpload,//function(file) {alert('onComplete')}, /** 单个文件上传完毕的响应事件 */
            //		onQueueComplete: function() {alert('onQueueComplete')}, /** 所有文件上传完毕的响应事件 */
            onUploadError: function (status, msg) { alert('onUploadError' + status + ":" + msg) } /** 文件上传出错的响应事件 */
        };

        var _t = new Stream(config);

        var existingMobileObj = ""; //已有对象


        //function onSelected(file) {
        //    var appElement = document.querySelector('[ng-controller=myCtrl]');
        //    var $scope = angular.element(appElement).scope();
        //    $scope.$apply;
        //}

        function CompleteUpload(file) {
            //alert(JSON.stringify(file));
            //return;
            var filename = JSON.parse(file.msg).filepath;
            var words = filename.split('\\');
            var md5 = words[words.length - 1];
            var SysFile = {
                "id": 0,
                "type": "SysFile",
                "properties": {
                    "filesize": file.size + "",
                    "name": file.name,
                    "filename": JSON.parse(file.msg).filepath,
                    "md5": md5

                }
            }
            //检查文件MD5是否已经存在
            FileExists(SysFile);
            var appElement = document.querySelector('[ng-controller=myCtrl]');
            var $scope = angular.element(appElement).scope();
            $scope.$apply;
            existingMobileObj = $scope.existingMobileObj;
        }

        //FileExists
        function FileExists(SysFile) {
            var $scope = angular.element(document.getElementById('m')).scope();
            var param = {
                "connectionId": 1,
                "user": {
                    "id": $scope.userinfo.user.id,
                    "type": "SysPerson"
                },
                "appName": "plm",
                "file": SysFile
            }
            $.ajax({
                cache: false,
                type: "POST",
                contentType: "application/json",
                url: '../app/invoke?fun=FileExists',
                data: JSON.stringify(param),

                success: function (data) {
                    var FileExistsResponse = JSON.parse(data);
                    if (FileExistsResponse.resFlag == 0) {
                        if (FileExistsResponse.result.id == 0) { //表示文件不存在
                            UploadFile(SysFile) //则上传的SysFile对象id=0
                        } else {
                            UploadFile(FileExistsResponse.result) //则上传的已经存在的SysFile
                        }
                    } else {
                        alert(FileExistsResponse.errMsg);
                    }
                }
            });
        }

        //UploadFile
        function UploadFile(SysFile) {
            var $scope = angular.element(document.getElementById('m')).scope();
            var param = {
                "connectionId": 1,
                "user": {
                    "id": $scope.userinfo.user.id,
                    "type": "SysPerson"
                },
                "appName": "plm",
                "file": SysFile
            }

            $.ajax({
                cache: false,
                type: "POST",
                contentType: "application/json",
                url: '../app/invoke?fun=UploadFile',
                data: JSON.stringify(param),

                success: function (data) {
                    var UploadFileResponse = JSON.parse(data);
                    if (UploadFileResponse.resFlag == 0) {
                        var doc = UploadFileResponse.result;
                        doc.id = 0;
                        doc.type = "SysDocumentRev"
                        correlate(existingMobileObj, doc, "PlmFolderDocument", 17)
                    } else {
                        alert(UploadFileResponse.errMsg);
                    }
                }
            });

        }

        //使有相互关系
        function correlate(objA, objB, relationName, childrenStrategy) {
            var graph = {
                "roots": [
                    {
                        "entity": objA,
                        "nodeId": 0,
                        "children": [
                            {
                                "entity": objB,
                                "relation": {
                                    "properties": {},
                                    "lId": 0,
                                    "lType": relationName,
                                    "objIdA": objA.id,
                                    "aClassType": objA.type,
                                    "objIdB": objB.id,
                                    "bClassType": objB.type
                                },
                                "nodeId": 1,
                                "children": [],
                                "strategy": childrenStrategy
                            }
                        ],
                        "strategy": 136
                    }
                ]
            };
            $.ajax({
                cache: false,
                type: "POST",
                contentType: "application/json",
                url: '../jridgeadvanced/batchdo',
                data: JSON.stringify(graph),

                success: function (data) {
                    var batchdoResponse = JSON.parse(data);
                    if (batchdoResponse.resFlag == 0) {
                        var $scope = angular.element(document.getElementById('m')).scope();
                        $scope.subfolder($scope.parentMobileObj);
                        $('.stream-files-scroll').text('');
                        $('#i_stream_message_container').text('');
                    } else {
                        alert(batchdoResponse.errMsg);
                    }

                }
            });
        }

    </script>
</body>
</html>